<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>批注工作记录</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form label-width="90px" ref="editForm">
          <el-form-item label="批注内容：" prop="remark">
            <el-input v-model="remark"
                      placeholder="批注内容"
                      size="small"
                      type="textarea"
                      maxlength="1000"
                      :autosize="{
               minRows: 6, maxRows: 12
                      }"
                      show-word-limit></el-input>
          </el-form-item>
          <el-form-item label="添加附件：">
            <uploadFileModle number="20" @getFile="getFile" ref="uploadFileModle" :sycnStatus="true"
                             fileType="interaction_add" :fileListPush="getList"></uploadFileModle>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button size="small" type="primary" @click="checkEditFn">确定提交</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {noteAnnotation, noteLogAdd, inteactionLogAdd} from "@/api/admin/outineWorke"

export default {
  props: ['visible', 'noteId', 'noteRemark', 'remarkType'], // recruitmentType examine 审核
  components: {},
  data() {
    return {
      dialogVisible: false,
      remark: '',
      getList: [],
      fileList: [],
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (!this.visible) {
        this.remark = ''
      } else {
        this.remark = this.noteRemark
      }
    }
  },
  created() {

  },
  methods: {
    getFile(option) {
      console.log('收到附件数据：', option)
      this.fileList = this.getJson(option)
    },
    checkEditFn() {
      if (!this.remark) {
        this.$message.error('填写备注内容')
        return
      }
      let file = []
      for (let item of this.fileList) {
        let a = {}
        a.name = item.name
        a.src = item.src
        file.push(a)
      }
      // remarkType 1 互动批注添加 2 例行工作批注添加
      if(Number(this.remarkType)===2){
        noteLogAdd({remark: this.remark, routine_id: this.noteId,file: JSON.stringify(file)}).then(res => {
          console.log(res)
          if (!res.code) {
            this.$message.success(res.msg)
            this.$emit('getFileListFn')
            this.closePOpup()
          } else {
            this.$message.error(res.msg)
          }
        })
      }else{
        inteactionLogAdd({remark: this.remark, routine_id: this.noteId,file: JSON.stringify(file)}).then(res => {
          console.log(res)
          if (!res.code) {
            this.$message.success(res.msg)
            this.$emit('getFileListFn')
            this.closePOpup()
          } else {
            this.$message.error(res.msg)
          }
        })
      }
      // noteAnnotation({remark: this.remark, id: this.noteId,remark_file: JSON.stringify(file)}).then(res => {
      //   console.log(res)
      //   if (!res.data) {
      //     this.$message.success(res.msg)
      //     this.$emit('getFileListFn')
      //     this.closePOpup()
      //   } else {
      //     this.$message.error(res.msg)
      //   }
      // })

    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 550px;
  height: 400px;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}
</style>


